package com.jse.jakarta;

import java.io.IOException;

import jakarta.websocket.CloseReason;
import jakarta.websocket.Endpoint;
import jakarta.websocket.EndpointConfig;
import jakarta.websocket.MessageHandler;
import jakarta.websocket.Session;

public class JseEndpoint extends Endpoint{
    	
		@Override
		public void onOpen(Session session, EndpointConfig config) {
			System.out.println("打开链接"+session.getId());
			
			session.addMessageHandler(new MessageHandler.Whole<String>() {
		         @Override
		         public void onMessage(String msg) {
		            try {
		               session.getBasicRemote().sendText(msg);
		            } catch (IOException e) { }
		         }
		      });
		}

		@Override
		public void onClose(Session session, CloseReason closeReason) {
			System.out.println("关闭了");
		}

		@Override
		public void onError(Session session, Throwable thr) {
			System.out.println("出错了");
		}
    	
    }